// chooseBankcard.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        wx.request({
            url: app.data.baseUrl + '/AibraUsb/bankcard/list.do',
            data: {
                openId: app.globalData.openid
            },
            success: function(res) {
                var check = []
                for (let i = 0; i < res.data.bcList.length; i++) {
                    check[i] = ''
                }
                check[0] = 'checked'
                that.setData({
                    bcList: res.data.bcList,
                    check: check
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    bindaddBankcard: function() {
        wx.redirectTo({
            url: "addBankcard/addBankcard"
        })
    },
    //选择提现指向的银行卡
    chooseCard: function(e) {
        var inde = e.currentTarget.dataset.index;

        var that = this;
        var check = that.data.check
        for (let i = 0; i < that.data.bcList.length; i++) {
            check[i] = ''
        }
        check[inde] = 'checked',
            that.setData({
                check: check
            })
        wx.request({
            url: app.data.baseUrl + '/AibraUsb/bankcard/setIsDefault.do',
            data: {
                openId: app.globalData.openid,
                bankCardId: that.data.bcList[inde].id

            },
            success: function(res) {
                wx.redirectTo({
                    url: '../withdrawCash'
                })
            }
        })
    }
})